import {
  request
} from '../../request/index'
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({

  data: {
    userinfo: {},
    playList: [],
    playCount: []
  },

  onLoad: function (options) {
    let userinfo = wx.getStorageSync('userinfo');

    let id = userinfo.userId

    this.getUserSongList(id)


    if (userinfo) {
      this.setData({
        userinfo
      })
    }

  },

  toLogin() {
    let {userinfo} = this.data
    if(userinfo.userId){
      wx.navigateTo({
        url: '/pages/userInfo/index?id='+userinfo.userId,
      });
    }else{
      wx.navigateTo({
        url: '/pages/login/index',
      });
    }
  },
  toDetail(){
    let {userinfo} = this.data
    if(userinfo.userId){
      wx.navigateTo({
        url: '/pages/follows/index?uid='+userinfo.userId,
      });
    }else{
      wx.navigateTo({
        url: '/pages/login/index',
      });
    }
  },

  toRecentPlay(){
    wx.navigateTo({
      url: '/pages/recentPlay/index',
    });
  },
  
  //获取用户歌单
  async getUserSongList(id) {
    let {
      data
    } = await request({
      url: "/user/playlist",
      data: {
        uid: id
      }
    })

    this.setData({
      playList: data.playlist,
    })



  }

})